package com.example.mall.client;

import com.example.mall.client.fallback.SearchFeignClientFactory;
import com.example.mall.doc.ProductsDoc;
import com.example.mall.query.ProductsQueryDto;
import com.example.mall.result.JSONResult;
import com.example.mall.result.PageList;
import feign.Request;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: xxxliu
 * @CreateTime: 2025-06-06
 * @Version: 1.0
 */
@FeignClient(value = "mall-service-search",fallbackFactory = SearchFeignClientFactory.class,configuration = SearchFeignClient.FeignConfig.class)
@RequestMapping("/search")
public interface SearchFeignClient {

    @RequestMapping(value = "/addProduct",method = RequestMethod.POST)
    public JSONResult addProduct(@RequestBody ProductsDoc doc);

    //批量添加课程
    @RequestMapping(value = "/batchAddProduct",method = RequestMethod.POST)
    public JSONResult batchAddProduct(@RequestBody ProductsDoc[] docs);

    // 3. 根据ID获取商品
    @GetMapping("/{id}")
    public JSONResult getById(@PathVariable Long id);

    @DeleteMapping("/{id}")
    public JSONResult deleteById(@PathVariable Long id);

    //删除课程
    @RequestMapping(value = "/deleteProduct",method = RequestMethod.POST)
    public JSONResult deleteProduct(@RequestBody ProductsDoc doc);

    //搜索课程
    @RequestMapping(value = "/searchProduct",method = RequestMethod.POST)
    public JSONResult searchProduct(@RequestBody ProductsQueryDto dto);

    @Configuration
    public class FeignConfig {
        @Bean
        public Request.Options options() {
            return new Request.Options(10000, 60000); // 设置连接和读取超时时间
        }
    }
}
